const BaseUrl = 'http://test-api.jikexia.net/api/';
function randomString(len) {
  len = len || 32;
  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  let maxPos = $chars.length;
  let pwd = '';
  for (let i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}
function formatDate() {
  let date = new Date(); //转换成Data();
  let y = date.getFullYear();
  let m = date.getMonth() + 1;
  m = m < 10 ? '0' + m : m;
  let d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  return y + '-' + m + '-' + d;
}
function unique(arr) {
  if (!Array.isArray(arr)) {
    console.log('type error!');
    return;
  }
  arr = arr.sort();
  let array= [arr[0]];
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] !== arr[i-1]) {
      array.push(arr[i]);
    }
  }
  return array;
}
function getJurisdiction(type,data) {
  let jurisdiction = JSON.parse(localStorage.getItem('subMenus'));
  let returnData = {};
  if(type === 1){
    let configArr = [];
    jurisdiction.forEach(item=>{
      if('/'+item.url === this.$route.path){
        configArr = item.child
      }
    });
    data.forEach(item=>{
      configArr.forEach(demo=>{
        if(item.key === demo.url) returnData[item.back] = true
      })
    });
    data.forEach(item=>{
      if(!returnData.hasOwnProperty(item.back)){
        returnData[item.back] = false
      }
    })
  }else{
    let configArr = [];
    jurisdiction.forEach(item=>{
      item.child.forEach(demo=>{
        if('/'+demo.url === this.$route.path){
          configArr = demo.child
        }
      })
    });
    data.forEach(item=>{
      configArr.forEach(demo=>{
        if(item.key === demo.url) returnData[item.back] = true
      })
    });
    data.forEach(item=>{
      if(!returnData.hasOwnProperty(item.back)){
        returnData[item.back] = false
      }
    })
  }
  return returnData
}
export {
  BaseUrl,
  formatDate,
  randomString,
  unique,
  getJurisdiction
}
